package edu.hawaii.wicket.page.scheduler;

import org.apache.wicket.markup.html.CSSPackageResource;
import org.apache.wicket.markup.html.IHeaderContributor;
import org.apache.wicket.markup.html.IHeaderResponse;
import org.apache.wicket.markup.html.JavascriptPackageResource;
import org.apache.wicket.markup.html.WebComponent;
/**
 * The calendar class. 
 * @author Gerolf Seitz
 * https://github.com/gseitz
 */
public class FullCalendar extends WebComponent implements IHeaderContributor { 
  private static final long serialVersionUID = 1L;
  private FullCalendarSettings settings = new FullCalendarSettings();
  /**
   * Constructor.
   * @param id id #
   */
  public FullCalendar(String id) { 
    super(id);
    setOutputMarkupId(true);

    add(JavascriptPackageResource.getHeaderContribution(FullCalendarResources.JQUERY_JS));
    add(JavascriptPackageResource.getHeaderContribution(FullCalendarResources.JS));
    add(JavascriptPackageResource.getHeaderContribution(FullCalendarResources.GCAL_JS));
    add(CSSPackageResource.getHeaderContribution(FullCalendarResources.CSS));
  } 
  /**
   * Renders the page head.
   * @param response a response.
   */
  public void renderHead(IHeaderResponse response) { 
    StringBuilder sb = new StringBuilder();
    sb.append("$('#");
    sb.append(getMarkupId(true));
    sb.append("').fullCalendar({");
    sb.append(settings.asJsonString());
    sb.append("})");

    response.renderOnDomReadyJavascript(sb.toString());
  } 

  /**
   * Gets calendar settings.
   * @return cal settings.
   */
  public FullCalendarSettings getSettings() { 
    return settings;
  } 
  /**
   * Sets calendar settings.
   * @param settings settings.
   */
  public void setSettings(FullCalendarSettings settings) { 
    this.settings = settings;
  }

} 